#include <iostream>
#include <string>

using namespace std;

bool isH(int num) {
    string str = to_string(num);
    int size = str.length();
    for (int i = 0; i < size / 2; ++i) {
        if (str[i] != str[size - i - 1]) {
            return false;
        }
    }
    return true;
}

int main() {
    int L, R, k;
    cin >> L >> R >> k;
    int count =0;
    for (int i = L; i < R; ++i) {
        int remain = i % k;
        if (remain == 2 && isH(i)) {
            count++;
        }
    }
    cout << count << endl;
}